//package com.zmn.plat.dubbo.impl.channel;
//
//import java.util.Arrays;
//import java.util.List;
//import java.util.Objects;
//
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dto.VtDTO;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.plat.business.interfaces.channel.ChannelCategBService;
//import com.zmn.plat.business.interfaces.channel.ChannelServiceCategoryBService;
//import com.zmn.plat.common.dto.KVDTO;
//import com.zmn.plat.common.dto.category.CategoryUnionInfoDRO;
//import com.zmn.plat.common.dto.channel.category.ChannelCategorySimpleSpellDIO;
//import com.zmn.plat.common.dto.channel.category.ChannelCategorySimpleSpellDRO;
//import com.zmn.plat.common.util.TreeUtil;
//import com.zmn.plat.services.interfaces.channel.ChannelServiceCategoryService;
//import org.apache.dubbo.config.annotation.Service;
//import org.springframework.cache.annotation.Cacheable;
//import com.zmn.common.dto.AreaDTO;
//import com.zmn.common.dto.KvDTO;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.reflect.BeanMapper;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.plat.business.interfaces.channel.ChannelBService;
//import com.zmn.plat.common.dto.category.CategoryDRO;
//import com.zmn.plat.common.dto.category.CategoryInfoDRO;
//import com.zmn.plat.common.dto.servcategory.ServCategoryDRO;
//import com.zmn.plat.common.exception.PlatException;
//import com.zmn.plat.dubbo.interfaces.channel.ChannelCategoryListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.model.entity.category.CategoryInfoDTO;
//import lombok.extern.log4j.Log4j2;
//
//import javax.annotation.Resource;
//import javax.validation.constraints.NotNull;
//
//
//@Log4j2
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//public class ChannelCategoryListRemoteServiceImpl implements ChannelCategoryListRemoteService {
//
//    @Resource
//    private ChannelBService channelBService;
//
//    @Resource
//    private ChannelCategBService channelCategBService;
//
//    @Resource
//    private ChannelServiceCategoryService channelServiceCategoryService;
//
//    @Resource
//    private ChannelServiceCategoryBService channelServiceCategoryBService;
//
//    // 渠道E特殊处理，临时使用
//    private static final Integer CHANNEL_WX_E_ID = 32837;
//    private static final Integer SERV_CATEG_ID_SDWX = 1007;
//
//    private static final Integer CATEG_ONE_ID_ZFXQ = 2981;
//    private static final Integer CATEG_ONE_ID_ZFXQ_BACK = 2979;
//    private static final String CATEG_ONE_NAME_ZFXQ = "砖缝修缮";
//    private static final Integer CATEG_ID_CZ = 2982;
//    private static final Integer CATEG_ID_CZ_BACK = 2980;
//    private static final String CATEG_NAME_CZ = "瓷砖";
//    private static final List<Integer> CITY_ID_LIST = Arrays.asList(500100, 440300, 360100, 510100);
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<KVDTO>> listCategoryTreeByChannelId(Integer channelId) {
//
//        if (NumberUtil.isNullOrZero(channelId)) {
//            return ResponseDTO.fail("参数不合法");
//        }
//        try {
//            List<KVDTO> kvdtos = channelServiceCategoryService.listAllCategoryByChannelId(channelId);
//            List<KVDTO> result = TreeUtil.buildTree(kvdtos, GlobalConsts.TOP_ID, GlobalConsts.LEVEL_3);
//            return ResponseDTO.success(result);
//        } catch (Exception e) {
//            log.error("ChannelCategoryListRemoteServiceImpl.listCategoryTreeByChannelId查询失败,原因:{}", e.getMessage(), e);
//            return ResponseDTO.fail("查询失败，程序异常");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ServCategoryDRO>> listServCategoryByChannelId(Integer channelId, Integer showType) {
//
//        log.info("ChannelCategoryListRemoteServiceImpl.listServCategoryByChannelId参数channelId：{}，showType：{}", channelId, showType);
//        try {
//            List<ServCategoryDRO> list = channelCategBService.listServCategoryByChannelId(channelId, showType);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("listServCategoryByChannelId error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:one:cid:'+#p0+'showtype:'+#p1+'servcategid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<CategoryDRO>> listCategoryOneByChannelIdAndServCategId(Integer channelId, Integer showType, Integer servCategId) {
//
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategoryOneByChannelIdAndServCategId参数channelId：{}，showType：{}", channelId, showType);
//        try {
//            List<CategoryDRO> dros = channelCategBService.listCategoryOneByChannelIdAndServCategId(channelId, showType, servCategId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:cid:'+#p0+'showtype:'+#p1+'categoneid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<CategoryInfoDRO>> listCategoryByChannelIdAndCategOneId(Integer channelId, Integer showType, Integer categOneId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategoryOneByChannelIdAndServCategId参数channelId：{}，showType：{}，categOneId：{}", channelId, showType, categOneId);
//
//        try {
//            List<CategoryInfoDRO> list = channelCategBService.listCategoryByChannelIdAndCategOneId(channelId, showType, categOneId);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:cid:'+#p0+'showtype:'+#p1+'servcategid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<CategoryInfoDRO>> listCategoryByChannelIdAndServCategId(Integer channelId, Integer showType, Integer servCategId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategoryByChannelIdAndServCategId参数channelId：{}，showType：{}，servCategId：{}", channelId, showType, servCategId);
//
//        try {
//            List<CategoryInfoDRO> list = channelCategBService.listCategoryByChannelIdAndServCategId(channelId, showType, servCategId);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:channelid:'+#p0+'servcategid:'+#p1+'categids:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<Integer>> listCategIdByChannelIdAndServCategIdAndCategIds(Integer channelId, Integer servCategId, List<Integer> categIds) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategIdByChannelIdAndServCategIdAndCategIds参数channelId：{}，servCategId：{}，categIds：{}", channelId, servCategId, categIds);
//
//        try {
//            List<Integer> list = channelCategBService.listCategIdByChannelIdAndServCategIdAndCategIds(channelId, servCategId, categIds);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:all:cid:'+#p0+'showtype:'+#p1+'servcategid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<CategoryInfoDRO>> listAllCategoryByChannelIdAndServCategId(Integer channelId, Integer showType, Integer servCategId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listAllCategoryByChannelIdAndServCategId参数channelId：{}，showType：{}，servCategId：{}", channelId, showType, servCategId);
//        try {
//            List<CategoryInfoDRO> list = channelCategBService.listCategoryByChannelIdAndServCategId(channelId, showType, servCategId);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<CategoryInfoDRO>> listShowCategByChannelId(Integer channelId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listShowCategByChannelId参数：channelId：{}", channelId);
//
//        try {
//            List<CategoryInfoDRO> list = channelCategBService.listShowCategByChannelId(channelId);
//            return ResponseDTO.success(list);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:categ:all:level:cid:'+#p0+'showtype:'+#p1", cacheNames = "redis5m")
//    public ResponseDTO<List<KvDTO<Integer, String>>> listAllLevelCategoryByChannelId(Integer channelId, Integer showType) {
//
//        log.info("ChannelCategoryListRemoteServiceImpl.listAllLevelCategoryByChannelId参数channelId：{}，showType：{}", channelId, showType);
//        try {
//            List<KvDTO<Integer, String>> kvDTOS = channelBService.listAllLevelCategoryByChannelId(channelId, showType);
//            return ResponseDTO.success(kvDTOS);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:servcateg:cid:'+#p0+'showtype:'+#p1+'cityid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<ServCategoryDRO>> listServCategoryByChannelIdAndCityId(Integer channelId, Integer showType, Integer cityId) {
//        //789
//        log.info("ChannelCategoryListRemoteServiceImpl.listServCategoryByChannelIdAndCityId参数channelId：{}，showType：{}，cityId：{}", channelId, showType, cityId);
//        try {
//            List<ServCategoryDRO> dros = channelCategBService.listServCategoryByChannelIdAndCityId(channelId, showType, cityId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelCategorySimpleSpellDRO>> listCategoryByChannelIdAndCityIdAndSimpleSpell(ChannelCategorySimpleSpellDIO channelCategorySimpleSpellDIO) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listServCategoryByChannelIdAndCityIdAndSimpleSpell参数：{}", channelCategorySimpleSpellDIO);
//        try {
//            List<ChannelCategorySimpleSpellDRO> dros = channelCategBService.listCategoryByChannelIdAndCityIdAndSimpleSpell(channelCategorySimpleSpellDIO);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<CategoryInfoDRO>> listCategoryByChannelIdAndCityIdAndServCategId(Integer channelId, Integer showType, Integer cityId, Integer servCategId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategoryByChannelIdAndCityIdAndServCategId参数channelId：{}，showType：{}，cityId：{}，servCategId：{}", channelId, showType, cityId, servCategId);
//
//        try {
//            List<CategoryInfoDTO> list = channelCategBService.listCategoryByChannelIdAndCityIdAndServCategId(channelId, showType, cityId, servCategId);
//            // 渠道E特殊处理
//            // ChanenlSpecialTreatment.treatment(channelId, cityId, showType, servCategId, list, baseCategoryService);
//            List<CategoryInfoDRO> dros = BeanMapper.mapList(list, CategoryInfoDRO.class);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<CategoryInfoDRO>> listCategoryByChannelIdAndCityIdAndServCategIds(Integer channelId, Integer showType, Integer cityId, List<Integer> servCategIds) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listCategoryByChannelIdAndCityIdAndServCategIds参数channelId：{}，showType：{}，cityId：{}，servCategIds：{}", channelId, showType, cityId, servCategIds);
//
//        try {
//            List<CategoryInfoDTO> list = channelCategBService.listCategoryByChannelIdAndCityIdAndServCategIds(channelId, showType, cityId, servCategIds);
//            // 渠道E特殊处理
//            // ChanenlSpecialTreatment.treatment(channelId, cityId, showType, servCategIds, list, baseCategoryService);
//            List<CategoryInfoDRO> dros = BeanMapper.mapList(list, CategoryInfoDRO.class);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<CategoryUnionInfoDRO>> listUnionCategoryByChannelIdAndCityIdAndServCategIds(Integer channelId, Integer cityId, List<Integer> servCategIds) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listUnionCategoryByChannelIdAndCityIdAndServCategIds参数channelId：{}，cityId：{}，servCategIds：{}", channelId, cityId, servCategIds);
//
//        try {
//            List<CategoryUnionInfoDRO> result = channelServiceCategoryBService.listUnionCategoryByChannelIdAndCityIdAndServCategIds(channelId, cityId, servCategIds);
//            return ResponseDTO.success(result);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<Boolean> isOpenCategory(Integer channelId, Integer showType, Integer cityId, Integer servCategId, Integer categTwoId) {
//        List<CategoryInfoDRO> items = this.listCategoryByChannelIdAndCityIdAndServCategId(channelId, showType, cityId, servCategId).getData();
//        boolean result = items.stream().anyMatch(item -> Objects.equals(item.getCategId(), categTwoId));
//        return ResponseDTO.success(result);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:area:cid:'+#p0+'showtype:'+#p1", cacheNames = "redis5m")
//    public ResponseDTO<List<AreaDTO>> listAreaByChannelId(Integer channelId, Integer showType) {
//
//        log.info("ChannelCategoryListRemoteServiceImpl.listAreaByChannelId参数：channelId：{}，showType：{}", channelId, showType);
//
//        try {
//            List<AreaDTO> dros = channelCategBService.listAreaByChannelId(channelId, showType);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:area:cid:'+#p0+'showtype:'+#p1+'servcategid:'+#p2", cacheNames = "redis5m")
//    public ResponseDTO<List<AreaDTO>> listAreaByChannelIdAndServCategId(Integer channelId, Integer showType, Integer servCategId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listAreaByChannelIdAndServCategId参数：channelId：{}，showType：{}，servCategId：{}", channelId, showType, servCategId);
//
//        try {
//            List<AreaDTO> dros = channelCategBService.listAreaByChannelIdAndServCategId(channelId, showType, servCategId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listServCategoryByChannelIdAndAreaId(Integer channelId, Integer cityId, Integer countyId) {
//        log.info("listServCategoryByChannelIdAndCountyId.参数：channelId：{}，cityId:{},countyId：{}", channelId, cityId, countyId);
//        try {
//            List<VtDTO> dros = channelCategBService.listServCategoryByChannelIdAndAreaId(channelId, cityId, countyId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listProductByChannelIdAndAreaIdAndServCategId(Integer channelId, Integer cityId, Integer countyId, Integer servCategId) {
//        log.info("ChannelCategoryListRemoteServiceImpl.listAreaByChannelIdAndServCategId参数：channelId：{}，cityId:{},countyId：{}，servCategId：{}", channelId, cityId, countyId, servCategId);
//
//        try {
//            List<VtDTO> dros = channelCategBService.listProductByChannelIdAndAreaIdAndServCategId(channelId, cityId, countyId, servCategId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//}
